package com.ruoyi.logistic.controller;


import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.NetworkJuniorBill;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkJuniorBillVo;
import com.ruoyi.logistic.service.NetworkJuniorBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/juniorBill")
@RestController
@Api(tags = "网点财务_站点预付款_下级账户管理")
public class NetworkJuniorBillController {
    @Autowired
    private NetworkJuniorBillService networkJuniorBillService;
    @Autowired
    private TableService tableService;

    @ApiOperation("显示下级账户管理列表")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkJuniorBill> networkJuniorBillList = networkJuniorBillService.selectAll(pageDate);
        if (networkJuniorBillList == null || networkJuniorBillList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkJuniorBillList);
        }
    }

    @ApiOperation("添加下级账户管理")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkJuniorBill networkJuniorBill){
        Boolean isAdd = networkJuniorBillService.insert(networkJuniorBill);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改下级账户管理")
    @PostMapping("/update")
    public R update(@RequestBody NetworkJuniorBill networkJuniorBill){
        Boolean isUpdate = networkJuniorBillService.update(networkJuniorBill);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除下级账户管理")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkJuniorBillService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("搜索下级账户管理")
    @PostMapping("/search")
    public R search(@RequestBody NetworkJuniorBillVo networkJuniorBillVo){
        List<NetworkJuniorBill> networkJuniorBillList = networkJuniorBillService.search(networkJuniorBillVo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkJuniorBill());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(networkJuniorBillList));
        jsonObject.put("fields", fieldList);
        if (networkJuniorBillList == null || networkJuniorBillList.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
}
